from pymongo import MongoClient
import pymongo
import os
import inference
import numpy as np
import sys
client = MongoClient(port=27017)
db=client['tiktok']
i=0
collist=['happyholi']
for col in collist:
    for item in db[col].find():
        if len(item['video_feature']['audio']['yamnet'])==0:
            if os.path.exists('E:\\wav_pi\\'+item['_id']+'.wav'):
                k=inference.yam(['E:\\wav_pi\\'+item['_id']+'.wav'])
            else:
                os.system('ffmpeg -i E:\\Tiktok\\Hashtag\\'+col+'\\'+item['_id']+'.mp4 E:\\wav_pi\\'+item['_id']+'.wav')
                k = inference.yam(['E:\\wav_pi\\' + item['_id'] + '.wav'])
            k=k.tolist()
            db[col].update_one({'_id': item['_id']}, {'$set':{'video_feature.audio.yamnet':k}})
            print('update success ',col,item['_id'])
            i += 1
            if i > 150:
                exit()

